<template>
	<view class="indexs">
		<view class="header header_lan" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="
          'height:' +
          gaodu +
          'px;line-height:' +
          gaodu +
          'px;top:' +
          gaodutops +
          'px;'
        ">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo">
						<image :src="imgUrl + '/dzx_img22.png'" mode="widthFix"></image>
					</view>
					<view class="index_wenben baise">{{
            $t("page_sharing_create.Start_group")
          }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom: 120rpx;'">
			<view class="faqipintuan_center">
				<view class="faqipintuan_item1">
					<view class="faqipintuan_item1_list">
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img27.png'"></image>
								<text>{{ $t("page_sharing_create.Group_name") }}</text>
							</view>
							<view class="faqipintuan_item1_r"><input type="text" data-field="title" @input="textInput"
									:placeholder="$t('page_sharing_create.placeholder1')" /></view>
						</view>
						<view class="baoguo_item2_cont" @tap="selectCountry()">
							<view class="baoguo_item2_cont_l">
								<image :src="imgUrl + '/dzx_img23.png'"></image>
								<text>{{ $t("page_sharing_create.shipping_country") }}</text>
							</view>
							<view class="baoguo_item2_cont_r">
								<text>{{guojianame? guojianame: $t("page_sharing_create.Please_select_country") }}</text>
								<image :src="imgUrl + '/dzx_img25.png'"></image>
							</view>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img24.png'"></image>
								<text>{{$t("page_sharing_create.Domestic_receiving_warehouse")}}</text>
							</view>
							<picker @change="bindPickerChange" :value="index" :range="cangkuarray">
								<view class="baoguo_item2_cont_r">
									<text>{{ cangkuarray[index] }}</text>
									<image :src="imgUrl + '/dzx_img25.png'"></image>
								</view>
							</picker>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img23.png'"></image>
								<text>{{ $t("page_sharing_create.Pick_up_address") }}</text>
							</view>
							<view class="faqipintuan_item1_r" @tap="selectAddress()">
								<text v-if="form.address_id == 0">{{
                  $t("page_sharing_create.Please_select_delivery_address")
                }}</text>
								<text v-else>{{ arrlist.country }}{{ arrlist.province }}{{ arrlist.city
                  }}{{ arrlist.district }}{{ arrlist.detail }}
									{{ arrlist.door }}</text>
								<image :src="imgUrl + '/dzx_img17.png'"></image>
							</view>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img26.png'"></image>
								<text>{{ $t("page_sharing_create.Channel_selection") }}</text>
							</view>
							<picker @change="bindPickerLineChange" :value="indexline" :range="chuhuolist">
								<view class="faqipintuan_item1_r">
									<text>{{ chuhuolist[indexline] }}</text>
									<image :src="imgUrl + '/dzx_img17.png'"></image>
								</view>
							</picker>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img78.png'"></image>
								<text>{{ $t("page_sharing_create.Start_time") }}</text>
							</view>
							<picker mode="date" :value="start_time" start="1970-01-01" @change="starttimeDateChange">
								<view class="faqipintuan_item1_r">
									<view class="picker">{{
                    start_time
                      ? start_time
                      : $t("page_sharing_create.p_Start_time")
                  }}</view>
									<image :src="imgUrl + '/dzx_img17.png'"></image>
								</view>
							</picker>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img78.png'"></image>
								<text>{{ $t("page_sharing_create.End_time") }}</text>
							</view>
							<picker mode="date" :value="birthday" start="1970-01-01" @change="bindDateChange">
								<view class="faqipintuan_item1_r">
									<view class="picker">{{
                    end_time ? end_time : $t("page_sharing_create.p_End_time")
                  }}</view>
									<image :src="imgUrl + '/dzx_img17.png'"></image>
								</view>
							</picker>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img50.png'"></image>
								<text>{{ $t("page_sharing_create.Shipping_weight") }}(kg)</text>
							</view>
							<view class="faqipintuan_item1_r">
								<input type="number" data-field="min_weight" @input="textInput"
									:placeholder="$t('page_sharing_create.p_Shipping_weight')" />
							</view>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img50.png'"></image>
								<text>{{ $t("page_sharing_create.Lumped_weight") }}(kg)</text>
							</view>
							<view class="faqipintuan_item1_r">
								<input type="number" data-field="predict_weight" @input="textInput"
									:placeholder="$t('page_sharing_create.p_Lumped_weight')" />
							</view>
						</view>
						<view class="faqipintuan_item1_cont">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + '/dzx_img79.png'"></image>
								<text>{{ $t("page_sharing_create.Maximum_group_size") }}</text>
							</view>
							<view class="faqipintuan_item1_r">
								<input type="number" data-field="join_member" @input="textInput"
									:placeholder="$t('page_sharing_create.p_Maximum_group_size')" />
							</view>
						</view>
						<view class="faqipintuan_item1_cont" style="padding-bottom: 18rpx">
							<view class="faqipintuan_item1_l">
								<image :src="imgUrl + 'dzx_img30.png'"></image>
								<text>{{ $t("page_sharing_create.Head_remarks") }}</text>
							</view>
						</view>
						<view class="faqipintuan_item1_txt">
							<textarea @input="textInput" data-field="group_leader_remark"
								:placeholder="$t('page_sharing_create.please_enter_note')" name="" id="" cols="30"
								rows="10"></textarea>
						</view>
					</view>
				</view>
				<view class="faqipintuan_item2" @tap="btnisshow">
					<image :src="imgUrl + (isshow ? 'dzx_img31.png' : 'dzx_img32.png')"></image>
					<view class="faqipintuan_item2_t1">
						{{ $t("page_sharing_create.Viewed_and_agreed") }}
						<text @tap="guizeshows">《{{ guizes.article_title }}》</text>
					</view>
				</view>
				<view class="baoguo_guize" v-if="guizeshow">
					<view class="baoguo_guize_banner">
						<view class="baoguo_guize_title">《{{ guizes.article_title }}》</view>
						<view class=""><rich-text :nodes="article_content"></rich-text></view>
						<view class="baoguo_guize_btns" @tap="isguizeshows">
							<view class="baoguo_guize_btns_txt">{{
                $t("page_sharing_create.Isee")
              }}</view>
						</view>
					</view>
				</view>

				<view class="baoguo_btns" @tap="submit">
					<view class="baoguo_btns_posi">
						<view class="baoguo_btn">{{
              $t("page_sharing_create.Start_group")
            }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();

	let request = require("../../utils/require");

	export default {
		data() {
			return {
				navH: app.globalData.navHeight,
				gaodu: app.globalData.height,
				imgUrl: app.globalData.imgUrl,
				cangkuarray: [],
				cangkuarr: "",
				arrlist: [],
				index: 0,
				isshow: false,
				chuhuoarr: [],
				chuhuolist: [],
				indexline: 0,
				start_time: "",
				end_time: "",
				guizeshow: false,
				guizes: {
					article_title: "",
				},
				guojianame:'',
				article_content: "",
				form: {
					title: "",
					shop_id: 0,
					address_id: 0,
					country_id: 0,
					line_id: 0,
					end_time: "",
					start_time: "",
					min_weight: "",
					max_people: 10,
					predict_weight: "300",
				},
			};
		},
		//滑动显示顶部
		onPageScroll: function(e) {},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			var that = this;
			that.cangkulist();
			that.getLine();
		},
		onShow() {
			var that = this;
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			console.log(currPage,9765)
			that.guize();
			that.guojianame = currPage.guojianame;
			that.form.country_id = currPage.guojiaid;
			if (currPage.data && currPage.data.address_id) {
				this.form["address_id"] = currPage.data.address_id;
				this.dizhilist();
			}
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {
			return {
				title: uni.getStorageSync("setting").desc,
				path: "/pages/index/index?user=" + this.user,
				imageUrl: "",
				success: function(res) {
					console.log("success22:" + JSON.stringify(res));
				},
				fail: function(err) {
					console.log("fail22:" + JSON.stringify(err));
				},
			};
		},
		methods: {
			selectCountry() {
				uni.navigateTo({
					url: "/pages/indexs/baoguoyg_guojia/baoguoyg_guojia",
				});
			},
			selectAddress() {
				uni.navigateTo({
					url: "/pages/pintuans/dizhi/dizhi?type=xuanze",
				});
			},
			bindDateChange(e) {
				this.end_time= e.detail.value
				this.form["end_time"] = e.detail.value;
			},
			starttimeDateChange(e) {
				this.start_time= e.detail.value
				this.form["start_time"] = e.detail.value;
			},
			textInput(e) {
				var field = e.currentTarget.dataset.field;
				this.form[field] = e.detail.value;
			},
			//选择仓库
			bindPickerChange: function(e) {
				console.log("picker发送选择改变，携带值为", e.detail.value);
				this.index= e.detail.value
				this.form["shop_id"] = e.detail.value;
			},

			//选择仓库
			bindPickerLineChange: function(e) {
				console.log("picker发送选择改变，携带值为", e.detail.value);
				this.indexline= e.detail.value
				this.form["line_id"] = e.detail.value;
			},
			getLine() {
				var that = this;
				var data = {
					token: uni.getStorageSync("token"),
				};
				request
					.post(
						`index.php?s=/api/package/line&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							var arrlist = [];
							for (var i in res.data.data.data) {
								arrlist.push(res.data.data.data[i].name);
							}
							console.log(arrlist, "arrlist?");
							this.form["line_id"] = res.data.data.data[0]["line_id"];
							that.chuhuoarr= res.data.data.data
							that.chuhuolist= arrlist
						}
					});
			},
			btnisshow() {
				this.isshow= !this.isshow
			},
			//地址列表
			dizhilist() {
				var that = this;
				var data = {
					token: uni.getStorageSync("token"),
				};
				request
					.post(
						`index.php?s=/api/address/lists&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							console.log(this.form.address_id, "addid");
							if (that.form.address_id != "") {
								var items = {};
								for (var i = 0; i < res.data.data.list.length; i++) {
									if (that.form.address_id == res.data.data.list[i].address_id) {
										items = res.data.data.list[i];
									}
								}
								that.arrlist= items
								that.arrlistquanbu= res.data.data.list
							} else {
								console.log(that.form.address_id, "addid3");
								that.arrlist= res.data.data.list[0]
								that.arrlistquanbu= res.data.data.list
							}
						}
					});
			},
			//仓库列表
			cangkulist() {
				var that = this;
				var data = {
					token: uni.getStorageSync("token"),
				};
				request
					.get(
						`index.php?s=/api/package/storage&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							var arrlist = [];
							for (var i = 0; i < res.data.data.length; i++) {
								arrlist.push(res.data.data[i].shop_name);
							}
							this.form["shop_id"] = arrlist[0]["shop_id"];
							this.cangkuarray= arrlist
							this.cangkuarr= res.data.data
						}
					});
			},
			submit() {
				var that = this;
				var data = this.form;
				data.token = uni.getStorageSync("token");
				data.line_id = that.chuhuoarr[that.indexline].id;
				data.shop_id = that.cangkuarr[that.index].shop_id;
				request
					.get(
						`index.php?s=/api/sharp.order/create&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							uni.showToast({
								title: res.data.data,
							});
							uni.navigateBack({
								delta: 1
							})
						} else {
							uni.showToast({
								icon: "none",
								title: res.data.data,
							});
						
						}
					});
			},
			jumpzuo() {
				uni.navigateBack();
			},
			isguizeshows() {
				this.guizeshow= false
			},

			guizeshows() {
				this.guizeshow= true
			},
			//拼团规则
			guize() {
				var that = this;
				var data = {
					token: uni.getStorageSync("token"),
				};
				request
					.post(
						`index.php?s=/api/article/report_note&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							var article_content = res.data.data.detail.article_content;
							article_content = article_content.replace(
								/<img/gi,
								'<img style="max-width:100%;height:auto;display:block" '
							);
							that.guizes= res.data.data.detail
							that.article_content= article_content
							console.log(that.guizes, 888);
						}
					});
			},
		},
	};
</script>

<style>
	@import url("./create.css");
</style>